exports.main = async context => {
    const cloud = context.cloud;
    const collectionName = 'pfMkProductMask';
    const products = context.data.products;
  
    try {
      const collection = cloud.db.collection(collectionName);
      const deletedCount = await clear(collection);
      const insertedIds = await collection.insertMany(products);
  
      return {
        success: true,
        result: insertedIds
      }
    } catch (error) {
      return {
        success: false,
        error
      };
    }
  };
  
  function clear(collection) {
    return collection.deleteMany({
      _id: { $type : 'string' }
    });
  }